/*
 * @(#)SlotTypeTransformer.java
 * Date 2013-09-02
 * Version 1.0
 * Author Jim Horner
 * Copyright (c)2012
 */


package us.hornerscorners.lamppost.registry.transformer.xds;

import java.util.Collections;
import java.util.List;

import javax.enterprise.context.ApplicationScoped;

import oasis.names.tc.ebxml_regrep.xsd.rim._3.SlotType1;
import oasis.names.tc.ebxml_regrep.xsd.rim._3.ValueListType;

import org.joda.time.DateTime;
import us.hornerscorners.lamppost.hl7v3common.utils.HL7Utils;

import us.hornerscorners.lamppost.model.document.Attribute;

import us.hornerscorners.lamppost.registry.constant.SlotName;

import us.hornerscorners.lamppost.transformer.AbstractTransformer;



/**
 * Class description
 *
 *
 * @version        v1.0, 2013-09-02
 * @author         Jim Horner
 */
@ApplicationScoped
public class SlotTypeTransformer extends AbstractTransformer<Attribute, SlotType1> {

    /**
     * Method description
     *
     *
     * @param attribute
     *
     * @return
     */
    @Override
    public SlotType1 transform(Attribute attribute) {

        return transform(attribute.getName(), attribute.getValues());
    }

    /**
     * Method description
     *
     *
     * @param name
     * @param value
     *
     * @return
     */
    public SlotType1 transform(SlotName name, DateTime value) {

//      return transform(
//          name,
//          DateTimeFormat.forPattern(UTCDateUtils.DATE_TIME_FORMAT).withZone(
//              DateTimeZone.forTimeZone(TimeZone.getDefault())).print(value));
        return transform(name, HL7Utils.toUTCDateTimeString(value));
    }

    /**
     * Method description
     *
     *
     * @param name
     * @param values
     *
     * @return
     */
    public SlotType1 transform(SlotName name, List<String> values) {

        return transform(name.getCode(), values);
    }

    /**
     * Method description
     *
     *
     * @param name
     * @param value
     *
     * @return
     */
    public SlotType1 transform(SlotName name, String value) {

        return transform(name, Collections.singletonList(value));

    }

    /**
     * Method description
     *
     *
     * @param name
     * @param values
     *
     * @return
     */
    public SlotType1 transform(String name, List<String> values) {

        SlotType1 result = new SlotType1();

        result.setName(name);

        ValueListType valueList = new ValueListType();

        valueList.getValue().addAll(values);
        result.setValueList(valueList);

        return result;
    }
}
